程式碼
#include <stdio.h> int globalVar = 77;// globalVar是全域變數 void function(){ int localVar = 44;//function函式的區域變數是loacalVar,賦值44 printf("function函式:\nGlobal Variable = %d, Local Variable = %d\n", globalVar, localVar); } int main(){ int localVar = 33;//main()函式的區域變數是loacalVar,賦值33 printf("主函式:\nGloabal Variable = %d, Local Variable = %d\n\n", globalVar, localVar); function(); //呼叫function函式已顯示其全域變數和區域變數 return 0; }
輸出結果